package com.autocar.reader.adapter;

import java.util.ArrayList;
import java.util.List;

import com.autocar.reader.R;
import com.autocar.reader.bean.WarnBean;
import com.autocar.reader.util.ImageUtils;
import com.org.any.autocar.fragment.IAuthorClickListener;
import com.org.any.autocar.fragment.IopenAddFrends;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ChatWarnAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	List<WarnBean> wlist = new ArrayList<WarnBean>();
	private IopenAddFrends addFrends = null;

	public ChatWarnAdapter(Context context,IopenAddFrends addFrends) {
		inflater = LayoutInflater.from(context);
		this.addFrends = addFrends;
	}

	public void setWList(List<WarnBean> wlist1) {
		this.wlist = wlist1;
		if (wlist != null) {
			notifyDataSetChanged();
		}
	}

	@Override
	public int getCount() {
		return wlist.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHodler viewHodler;
		if (convertView == null) {
			viewHodler = new ViewHodler();
			convertView = inflater.inflate(R.layout.chat_warn_item, null);
			viewHodler.nameTv = (TextView) convertView
					.findViewById(R.id.chat_warn_item_tv_name);
			viewHodler.picIv = (ImageView) convertView
					.findViewById(R.id.chat_warn_item_iv_pic);
			viewHodler.timeTv = (TextView) convertView
					.findViewById(R.id.chat_warn_item_tv_time);
			viewHodler.commentTv = (TextView) convertView
					.findViewById(R.id.chat_warn_item_tv_comment);
			viewHodler.replyCmTv = (TextView) convertView
					.findViewById(R.id.chat_warn_item_tv_reply_comment);
			convertView.setTag(viewHodler);
		} else {
			viewHodler = (ViewHodler) convertView.getTag();
		}
		final WarnBean bean = wlist.get(position);
		viewHodler.nameTv.setText(bean.getUname());
		viewHodler.timeTv.setText(bean.getAddtime());
		viewHodler.commentTv.setText(bean.getComment());
		ImageUtils.fb.display(viewHodler.picIv, bean.getPhoto());
		Log.i("test", "phone2 : "+bean.getPhoto());
		convertView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				addFrends.toWarn(bean);
			}
		});
		viewHodler.picIv.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				addFrends.openAuthor(bean.getUid());
			}
		});
		viewHodler.replyCmTv.setVisibility(View.GONE);
		return convertView;
	}

	class ViewHodler {
		TextView titleTv;
		TextView nameTv;
		TextView commentTv;
		TextView replyCmTv;
		TextView timeTv;
		ImageView picIv;
	}

}
